package com.sample.multilingual.controller;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sample-multilingual/*")
public class MultilingualController implements MessageSourceAware {
	private static final Logger logger = LoggerFactory.getLogger(MultilingualController.class); 

	private MessageSource messageSource;
	
	@Override
	public void setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
	}
	
	@RequestMapping(value = "/select.json", method = {RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> select(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
//		map.put("resource", messageSource.getMessage("bbs.title", null, request.getLocale()));
		map.put("resource", messageSource.getMessage("bbs.title2", null, request.getLocale()));
		return map;
	}

}
